/**
 * Created by Administrator on 2016/4/20.
 */
/**
 * Created by Administrator on 2016/3/25.
 */
$(function(){
    $(".gContainer img").mousedown(function(){
        $(this).attr("src","images/gWant1.png");
    });
    $(".gContainer img").mouseup(function(){
        $(this).attr("src","images/gWant.png");
    });

    $.ajax({
        url: "hxclub/activity/byIdContent.do",
        async: false,
        type : "get",
        dataType : "json",
        data:{id:id1},
        success : function(data){console.info(data)
            var $varietyContent = $('#content'), varietyHtml = template('detail', data);
            $varietyContent.html(varietyHtml);
            var imgs=$(".l_content img").length;

            if(imgs>1){
                $(".l_content img:first").hide();
                $(".l_content img:last").show();
            }
            if(imgs==1){
                $(".l_content img:first").show();
            }
             var $varietyContent = $('#nav_fangwen'), varietyHtml = template('nav_list', data);
             $varietyContent.html(varietyHtml);

            $(".gwant").click(function(){
                $.ajax({
                    url: "hxclub/sys/heart.do",
                    async: false,
                    type : "post",
                    dataType : "json",
                    success:function(d){
                        if(d.success){
                            var datatime = $("#shijian").val();

                            if(datatime == '1'){ // baoming
                                $(".timeout p").html("该活动已报名");
                                $(".register,.timeout").show();
                                $(".timeout .sure").mousedown(function(){
                                    $(".sure img").attr("src","images/galert3.png");
                                });
                                $(".timeout .sure").mouseup(function(){
                                    $(".sure img").attr("src","images/galert1.png");
                                    $(".timeout,.register").hide();
                                });
                            } else if(datatime == '2'){ // guoqi
                                $(".timeout p").html("该活动已过期");
                                $(".register,.timeout").show();
                                $(".timeout .sure").mousedown(function(){
                                    $(".sure img").attr("src","images/galert3.png");
                                });
                                $(".timeout .sure").mouseup(function(){
                                    $(".sure img").attr("src","images/galert1.png");
                                    $(".timeout,.register").hide();
                                });
                            } else {
                                $(".register,.center").show();
                            }
                        }
                        else{
                            //alert("请先登录后再报名");
                            $(".register,.login").show();
                            $(".login .less").mousedown(function(){
                                $(".less img").attr("src","images/galert4.png");
                            });
                            $(".login .less").mouseup(function(){
                                $(".less img").attr("src","images/galert2.png");
                            });
                            $(".login .del").click(function(){
                                $(".login,.register").hide();
                            });
                            $(".login .sure").mousedown(function(){
                                $(".sure img").attr("src","images/galert3.png");
                            });
                            $(".login .sure").mouseup(function(){
                                $(".sure img").attr("src","images/galert1.png");
                                window.location.href = 'login.html?redirectUrl=allactive.html?id='+id1;
                            });

                        }
                    }
                });
            })
        }
    });

    $.getJSON("hxclub/activity/activitys.do",{pid:id1,pageNo:1,pageSize:100},function(json){
        console.info(json)
        var $varietyContent = $('#drbd'), varietyHtml = template('detai2', json);
        $varietyContent.html(varietyHtml);
    })


    $(".center .less").mousedown(function(){
        $(".less img").attr("src","images/galert4.png");
    });
    $(".center .less").mouseup(function(){
        $(".less img").attr("src","images/galert2.png");
    });
    $(".center .del").click(function(){
        $(".center,.register").hide();
    });
    $(".center .sure").mousedown(function(){
        $(".sure img").attr("src","images/galert3.png");
    });
    $(".center .sure").mouseup(function(){
        $(".sure img").attr("src","images/galert1.png");
    });
    $(".center .sure").mouseup(function(){
        $.ajax({
            method:"POST",
            url:"hxclub/activity/join.do",
            data:{
                //uid:uid,
                aid:id1
            },
            dataType:"JSON",
            success:function(data){
                if(data.statusCode==200){
                    //alert(data.data);
                    $(".timeout p").html(data.data);
                    $(".timeout").show();
                    $(".timeout .sure").mousedown(function(){
                        $(".sure img").attr("src","images/galert3.png");
                    });
                    $(".timeout .sure").mouseup(function(){
                        $(".sure img").attr("src","images/galert1.png");
                        $(".timeout").hide();
                    });
                }else{
                    //alert(data.data);
                    $(".timeout p").html(data.data);

                    $(".timeout").show();
                    $(".timeout .sure").mousedown(function(){
                        $(".sure img").attr("src","images/galert3.png");
                    });
                    $(".timeout .sure").mouseup(function(){
                        $(".sure img").attr("src","images/galert1.png");
                        $(".timeout").hide();
                    });
                }
            }

        })
    })
});
